//Page Object
const { request } = require('../../utils/request')
let recordResTimeHandler :any = null;
Page({
  data: {
    
  },
  //options(Object)
  onLoad: function(options){
    let id = options.id;
    if(id){
      this.getCurRecordData(id)
    }else {
      wx.navigateBack({
        delta: 1,
      })
    }
  },
  getCurRecordData(id:string){
    if(recordResTimeHandler){
      clearInterval(recordResTimeHandler)
    }
    // this.showLoading()
    recordResTimeHandler = setInterval(()=>{
      request({
        url:'/records/'+id,
        success(rData:any){
          console.log('rData:',rData)
          // 状态 1=未完成 2=已完成 3=生成失败
          if(rData.status !== 1){
            clearInterval(recordResTimeHandler)
            // that.hideLoading()
            wx.reLaunch({
              url:'/pages/index/index'
            })
          }
        }
      })
    },1000)
  },
  cancel(){
    clearInterval(recordResTimeHandler)
  },
  onHide(){
    clearInterval(recordResTimeHandler)
  },
  onUnload(){
    clearInterval(recordResTimeHandler)
  }
});